using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DAO;
using DTO;

namespace Presentation
{
    public partial class FrmHangGanHet : Form
    {
        public FrmHangGanHet()
        {
            InitializeComponent();
        }

        private void FrmHangGanHet_Load(object sender, EventArgs e)
        {
            try
            {
                //hang gan het
                DuocPhamDao dpDao = new DuocPhamDao();
                DuocPhamDto[] dpDto = dpDao.SelectHangganhet();
                //hang can ngay(30 ngay)
                DuocPhamDto[] canngay = dpDao.SelectHangcanngay(30);

                if(dpDto.Length > 0 && canngay.Length > 0)
                {
                    label1.Visible = true;
                    label2.Visible = true;
                    btnIn.Visible = true;
                    button1.Visible = true;
                    dgvHangganhet.Visible = true;
                    dgvHangcanngay.Visible = true;

                    dgvHangganhet.AutoGenerateColumns = false;
                    dgvHangganhet.DataSource = dpDto;

                    dgvHangcanngay.AutoGenerateColumns = false;
                    dgvHangcanngay.DataSource = canngay;
                }
               if(dpDto.Length > 0 && canngay.Length <= 0)
               {
                   btnIn.Visible = true;
                   label1.Visible = true;
                   dgvHangganhet.Visible = true;
                   dgvHangcanngay.Visible = false;
                   label2.Visible = false;
                   button1.Visible = false;

                   dgvHangganhet.AutoGenerateColumns = false;
                   dgvHangganhet.DataSource = dpDto;
               }
               if (dpDto.Length <= 0 && canngay.Length > 0)
               {
                   dgvHangcanngay.Left = 10;
                   dgvHangcanngay.Top = 50;
                   button1.Left = 250;
                   button1.Top = 10;
                   label2.Left = 10;
                   label2.Top = 20;
                   label2.Visible = true;
                   button1.Visible = true;
                   label1.Visible = false;
                   btnIn.Visible = false;
                   dgvHangganhet.Visible = false;
                   dgvHangcanngay.Visible = true;

                   dgvHangcanngay.AutoGenerateColumns = false;
                   dgvHangcanngay.DataSource = canngay;
               }
            }
            catch (Exception exp)
            {

                throw new Exception(exp.ToString());
            }
        }

        private void btnIn_Click(object sender, EventArgs e)
        {

        }

        private void dgvHangganhet_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            DataGridView grv = (DataGridView)sender;
            Utils.MakeSothutuColumn(grv, "itemStt");
        }

        private void dgvHangcanngay_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            DataGridView grv = (DataGridView)sender;
            Utils.MakeSothutuColumn(grv, "itemStt1");
        }
    }
}